import pytest
import sqlite3
import time

@pytest.fixture()
def dbconnection():
    connection = sqlite3.connect("funds.db")
    print("数据库连接成功")
    yield connection
    connection.close()
    print("数据库连接已关闭")

@pytest.fixture(autouse=True)  #设置为True让autouse生效
def time_connct():
    start_time = time.time()
    yield
    spend_time = time.time() - start_time
    print("耗时{}秒".format(spend_time))

def test_case1(dbconnection):
    cursor1 = dbconnection.cursor()
    sql = "select count(1) from fund;"
    cursor1.execute(sql)
    result = cursor1.fetchone()[0]
    assert result == 11202

def test_case2(dbconnection):
    cursor1 = dbconnection.cursor()
    sql = "select count(1) from fund;"
    cursor1.execute(sql)
    result = cursor1.fetchone()[0]
    assert result == 11201

if __name__ == '__main__':
    pytest.main(['-s', 'mengfeiyuan.py'])